<template>
    <div id="list">
        <!-- 头部刷新区域 -->
        <div class="setdiv">
            <span>订单列表</span>
            <el-button class="refreshRight" plain icon="el-icon-refresh" @click="shuaxin">刷新</el-button>
        </div>
        <div id="button">
            <el-button @click="qbdd()" class="anniu" type="primary" size="medium" plain>全部订单</el-button>
            <el-button @click="dfk()" class="anniu" type="primary" size="medium" plain>待付款</el-button>
            <el-button @click="dfh()" class="anniu" type="primary" size="medium" plain>代发货</el-button>
            <el-button @click="yfh()" class="anniu" type="primary" size="medium" plain>已发货</el-button>
            <el-button @click="ywc()" class="anniu" type="primary" size="medium" plain>已完成</el-button>
            <el-button @click="ygb()" class="anniu" type="primary" size="medium" plain>已关闭</el-button>
        </div>
        <el-card>
            <el-collapse v-model="activeNames">
                <el-collapse-item title="筛选查询" name="1">
                    <div id="input1">
                        关键词<el-input class="input" v-model="formInline.ordernum" placeholder="订单号/商品货号"></el-input>
                        收货人<el-input class="input" v-model="formInline.userid" placeholder="用户昵称/手机号"> </el-input>
                        提交时间<el-select v-model="formInline.select" class="input" slot="prepend" placeholder="请选择时间">
                            <el-option label="2022" value="1"></el-option>
                            <el-option label="2021" value="2"></el-option>
                            <el-option label="2020" value="3"></el-option>
                        </el-select>
                    </div>
                    <div id="anniu1">
                        <el-button type="info" @click="chongzhi" plain>重置</el-button>
                        <el-button type="info" @click="Screening" plain>筛选</el-button>
                    </div>
                </el-collapse-item>
            </el-collapse>
            <div id="shuju">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>数据列表</span>
                        <!-- 批量删除按钮 -->
                        <el-button style="float: right; padding: 3px 0" type="text" @click="batchDelSure">批量删除</el-button>
                    </div>
                    <div id="card">
                        <el-table :data="tableData" border style="width: 100%" @selection-change="selectCheck">
                            <el-table-column type="selection" width="55">
                            </el-table-column>
                            <el-table-column fixed prop="id" label="序号" width="90">
                            </el-table-column>
                            <el-table-column prop="ordernum" label="订单编号" width="150">
                            </el-table-column>
                            <el-table-column prop="subtime" label="提交时间" width="150">
                            </el-table-column>
                            <el-table-column prop="phone" label="用户账号" width="150">
                            </el-table-column>
                            <el-table-column prop="money" label="订单金额" width="100">
                            </el-table-column>
                            <el-table-column prop="paymethod" label="支付方式" width="100">
                            </el-table-column>
                            <el-table-column prop="source" label="订单来源" width="120">
                            </el-table-column>
                            <el-table-column prop="type" label="订单状态" width="150">
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="100">
                                <template slot-scope="scope">
                                    <el-button type="text" @click="handleEdit(scope.row)">查看详情</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                </el-card>
            </div>
            <!-- 分页设置 -->
            <div id="fenye">
                <div class="block">
                    <el-pagination background :page-sizes="[5, 10, 20, 30]" layout="total, sizes, prev, pager, next, jumper" :total="userlist.length" :page-size="eachNum" :current-page.sync="nowPage">
                    </el-pagination>
                </div>
            </div>
            <!-- 查看详情弹出框 -->
            <div>
                <el-dialog title="订单详情" :visible.sync="CheckDialogVisible" width="50%" :before-close="editClose">
                    <!-- 查看详情表-->
                    <el-form ref="editTableData" :model="editTableData" label-width="80px">
                        <el-form-item prop="id" label="序号">
                            <el-input v-model="editTableData.id"></el-input>
                        </el-form-item>
                        <el-form-item prop="ordernum" label="订单编号">
                            <el-input v-model="editTableData.ordernum"></el-input>
                        </el-form-item>
                        <el-form-item prop="subtime" label="提交时间">
                            <el-input v-model="editTableData.subtime"></el-input>
                        </el-form-item>
                        <el-form-item prop="userid" label="用户账号">
                            <el-input v-model="editTableData.userid"></el-input>
                        </el-form-item>
                        <el-form-item prop="money" label="订单金额" width="150">
                            <el-input v-model="editTableData.money"></el-input>
                        </el-form-item>
                        <el-form-item prop="paymethod" label="支付方式" width="150">
                            <el-input v-model="editTableData.paymethod"></el-input>
                        </el-form-item>
                        <el-form-item prop="source" label="订单来源" width="200">
                            <el-input v-model="editTableData.source"></el-input>
                        </el-form-item>
                        <el-form-item prop="type" label="订单状态" width="200">
                            <el-input v-model="editTableData.type"></el-input>
                        </el-form-item>
                    </el-form>
                    <span slot="footer" class="dialog-footer">
                        <el-button type="primary" @click="editClose">确 定</el-button>
                    </span>
                </el-dialog>
            </div>
        </el-card>
    </div>
</template>
<style lang="less" scopd>
.el-collapse-item__content {
    margin-top: 30px;
}
#button {
    margin-top: -30px;
    margin-bottom: 10px;
}
// #xiala{
//   background-color: red;
// }
.setdiv {
    background-color: #f2f2f2;
    padding: 17.5px 0;
    position: relative;
}
.setdiv > span {
    margin-left: 20px;
}
.refreshRight {
    position: absolute;
    right: 20px;
    top: 8px;
}
.anniu {
    width: 100px;
    height: 40px;
    margin-top: 40px;
    text-align: center;
}
.box_card {
    margin-top: 10px;
}
.input {
    width: 200px;
    margin-left: 20px;
    margin-right: 50px;
}
#anniu1 {
    text-align: center;
    margin-top: 40px;
}
#input1 {
    text-align: center;
}
#card {
    margin-top: 20px;
}
#shuju {
    margin-top: 10px;
}
#fenye {
    margin-top: 10px;
    text-align: center;
}

.el-collapse-item__header {
    padding-left: 18px;
    font-size: 16px;
    height: 56px;
    background-color: rgb(242, 242, 242);
}
</style>
<script>
import date from "../../components/package";
export default {
    data() {
        return {
            input: "",
            input1: "",
            input2: "",
            input3: "",
            select: "",
            formInline: {
                ordernum: "",
                select: "",
                userid: "",
            },
            CheckDialogVisible: false,
            qd: false,
            editTableData: {
                id: "",
                ordernum: "",
                subtime: "",
                userid: "",
                money: "",
                paymethod: "",
                soourcr: "",
                type: "",
            },
            activeNames: [""],
            // 头部折叠框
            activeNames: ["1"],
            // 当前页
            nowPage: 1,
            // 每页显示五条
            eachNum: 5,
            // 存储总的数据
            userlist: [],
            batchDelFrom: {},
        };
    },
    created() {
        // this.getUserList();
        this.getOrdersList();
    },

    methods: {
        batchDelSure() {
            this.$confirm("确认删除所选退款信息？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                console.log(this.batchDelFrom);
                let str = "";
                for (let i = 0; i < this.batchDelFrom.length; i++) {
                    if (this.batchDelFrom[i].num) {
                        str = str + `"${this.batchDelFrom[i].name}"` + " ";
                    }
                }
                this.batchDel();
            });
        },
        batchDel() {
            this.$axios({
                url: "/refund_information1",
                method: "post",
                data: this.batchDelFrom,
            }).then((res) => {
                if (res.data.data.code == 200) {
                    this.getOrdersList();
                    this.$message({
                        message: "删除成功",
                        type: "success",
                    });
                } else {
                    this.$message({
                        message: "删除失败",
                        type: "warning",
                    });
                }
            });
        },
        selectCheck(selection) {
            this.batchDelFrom = selection;
        },
        // 初始化获取所有数据
        getOrdersList() {
            this.$axios({
                url: "/orders/getallorders",
                // method: "get",
            }).then((res) => {
                res.data.data.filter((v) => {
                    // 改变获取到时间的样式
                    v.subtime = date.dateFn(v.subtime);
                });
                this.userlist = res.data.data;
            });
        },
        chongzhi() {
            this.nowPage = 1;
            // this.getUserList();
            this.formInline.ordernum = "";
            (this.formInline.userid = ""),
                (this.formInline.select = ""),
                this.getOrdersList();
        },
        Screening() {
            this.nowPage = 1;

            this.$axios({
                url: "/orders/getChaXun1",
                params: {
                    ordernum: this.formInline.ordernum,
                    userid: this.formInline.userid,
                    time: this.formInline.select,
                },
            }).then((res) => {
                console.log(res.data);
                if (res.data.code == 200) {
                    this.userlist = res.data.data;
                }
            });
        },
        // 选项卡部分
        qbdd() {
            this.$router.push("list");
        },
        editClose() {
            this.CheckDialogVisible = false;
        },
        dfk() {
            this.$router.push("dfk");
        },
        dfh() {
            this.$router.push("dfh");
        },
        yfh() {
            this.$router.push("yfh");
        },
        ywc() {
            this.$router.push("ywc");
        },
        ygb() {
            this.$router.push("ygb");
        },
        handleEdit(data) {
            this.CheckDialogVisible = true;
            // console.log(data);
            this.editTableData = data;
            // console.log(this.editTableData);
            // this.eidtTableData = { ...data };
        },
        // 刷新
        shuaxin() {
            this.$router.go(0);
            this.$message({
                message: "刷新成功",
                type: "success",
            });
        },
    },
    // 分页计算
    computed: {
        tableData() {
            return this.userlist.slice(
                (this.nowPage - 1) * this.eachNum,
                this.nowPage * this.eachNum
            );
        },
    },
};
</script>


